package com.bert.thymeleafgenerator.controller;

import com.bert.thymeleafgenerator.mapper.MokMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@RestController
public class MokController {

    @Resource
    private MokMapper testMapper;

    @GetMapping("/ttt")
    public List<Map<String, Object>> getZdReadonly(){
//        String bm, String qzzd, String tjzd, String tj
        String stored = "call getinfo(varchar bm, varchar qzzd, varchar tjzd, varchar tj)";
        String s = new String();
        Pattern pattern = Pattern.compile("\\(([\\s\\S])*?\\)");
        Matcher matcher = pattern.matcher(stored);
        while (matcher.find()){
            System.out.println(matcher.group());
            s = matcher.group().substring(1, matcher.group().length() -1);
        }
        System.out.println(s);
        String[] t = s.split(",");
        List list = new ArrayList();
        for (int i = 0; i < t.length; i++) {
            System.out.println(t[i]);
            String[] temp = t[i].split("\\s+");
            System.out.println(temp[0]);
            list.add(temp[0]);
        }

        String bm = "1int";
        String qzzd = "*";
        String tjzd = "id";
        String tj = "1";
        List<Map<String, Object>> list1 = testMapper.getZdReadonly(bm,qzzd,tjzd,tj);
        return list1;
    }
}
